//
//  Home_Search_ResCell.m
//  HuaRun2
//
//  Created by admin on 17/9/6.
//  Copyright © 2017年 Sunny. All rights reserved.
//

#import "Home_Search_ResCell.h"

#import "LineView.h"
#import "Home_Search_ResModel.h"

@interface Home_Search_ResCell ()
    
//线1
@property (nonatomic, strong) LineView * line1;
@end;

@implementation Home_Search_ResCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
#pragma mark - life cycle

- (void)dealloc {
    NSLog(@"%@ dealloc", [self class]);
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self viewInit];
        [self layoutInit];
    }
    return self;
}
    
- (void)viewInit {
    
    [super viewInit];
    [self.contentView addSubview:self.flagView];
    [self.contentView addSubview:self.valueLab1];
    [self.contentView addSubview:self.valueLab2];
    [self.contentView addSubview:self.line1];

}
    
- (void)layoutInit {
    
//    [super layoutInit];
    
    weakself(ws);
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.contentView).offset(kMargin10);
        make.right.mas_equalTo(ws.contentView).offset(-kMargin10);
        make.top.mas_equalTo(ws.contentView).offset(0);
        make.bottom.mas_equalTo(ws.contentView).offset(0);
    }];
    
    [self.flagView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(ws.backView);
        make.left.mas_equalTo(ws.backView).offset(kMargin10);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];

    [self.valueLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.backView).offset(kMargin10/2);
        make.left.mas_equalTo(ws.flagView.mas_right).offset(kMargin10);
        make.right.mas_equalTo(ws.backView).offset(-kMargin10);
        make.height.mas_equalTo(20);
    }];
    
    [self.valueLab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.mas_equalTo(ws.valueLab1);
        make.top.mas_equalTo(ws.valueLab1.mas_bottom).offset(0);
    }];
    
    [self.line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(ws.backView);
        make.height.mas_equalTo(1);
        make.left.mas_equalTo(ws.backView).offset(kMargin10);
        make.right.mas_equalTo(ws.backView).offset(-kMargin10);
    }];
}
    
#pragma mark setter getter
- (void)setResModel:(Home_Search_ResModel *)resModel {
    _resModel = resModel;
 
    _valueLab1.text = [NSString showSpaceStringWithStr:resModel.name];
    _valueLab2.text = [NSString showSpaceStringWithStr:resModel.accountName];
    
    if (![NSString isemptyStr: resModel.type]) {
        NSString * imageName = @"";
        //        account、contact、meeting
        //如果是公司
        if ([resModel.type isEqualToString:@"account"]) {
            imageName = @"公司123";
        }else if ([resModel.type isEqualToString:@"contact"]) {
            imageName = @"lianxciren001";
        }else if ([resModel.type isEqualToString:@"meeting"]) {
            imageName = @"icon_huiyi01";
        }else if ([resModel.type isEqualToString:@"all"]) {
            imageName = @"icon_huiyi01";
        }
        
        _flagView.image = [UIImage imageNamed:imageName];
    }
}
    
- (UILabel *)valueLab1 {
    if (!_valueLab1) {
        self.valueLab1 = [UILabel new];
        _valueLab1.textAlignment = NSTextAlignmentLeft;
        _valueLab1.font = kGeneralFontSize;
        _valueLab1.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _valueLab1.text = @"英文民";
        //        _valueLab1.backgroundColor = kRandomColor;
    }
    return _valueLab1;
}
    
- (UILabel *)valueLab2 {
    if (!_valueLab2) {
        self.valueLab2 = [UILabel new];
        _valueLab2.textAlignment = NSTextAlignmentLeft;
        _valueLab2.font = kGeneralFontSize;
        _valueLab2.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _valueLab2.text = @"中文名字";
        //        _valueLab2.backgroundColor = kRandomColor;
    }
    return _valueLab2;
}
    
- (UIImageView *)flagView {
    if (!_flagView) {
        self.flagView = [UIImageView new];
        _flagView.image = [UIImage imageNamed:@"lianxciren001"];
    }
    return _flagView;
}
- (LineView *)line1 {
    if (!_line1) {
        self.line1 = [LineView new];
    }
    return _line1;
}
@end
